﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Eis51.CampanyCMS.Business.BaseInfoMng;
using Eis51.CampanyCMS.Business;
using Eis51.CampanyCMS.Business.OnlineService;
using Eis51.CampanyCMS.Model.OnlineService;
using Eis51.CampanyCMS.Model;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.UI.Admin.OnlineService
{
    public partial class list1 : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
        }

        public void InitData()
        {
            this.dbServices.Data = BaseMyChatToolsBLL.GetInstance().GetMyChatTools(AppContext.CurrentAdministrator.UserName);
            this.dbServices.DataBind();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            foreach (DataGridItem gvRow in dbServices.Items)
            {
                if (((CheckBox)(gvRow.Cells[0].FindControl("cbItem"))).Checked)
                {
                    HiddenField txtSeqno = gvRow.FindControl("txtSeqno") as HiddenField;
                    BaseMyChatToolsBLL.GetInstance().Delete(BaseMyChatToolsBLL.GetInstance().Get(new BaseMyChatTools.Key(int.Parse(txtSeqno.Value))));
                }
            }
            InitData();
        }

        protected void dgNews_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Header)
            {
                CheckBox cbxAll = e.Item.FindControl("cbxAll") as CheckBox;
                if (cbxAll != null)
                    cbxAll.Attributes.Add("onclick", "javascript:return SelectAll('" + this.dbServices.ClientID + "');");
            }

            if (e.Item.ItemType == ListItemType.AlternatingItem ||
              e.Item.ItemType == ListItemType.Item)
            {

            }
        }

        protected void dgNews_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Remove":

                    BaseMyChatToolsBLL.GetInstance().Delete(BaseMyChatToolsBLL.GetInstance().Get(new BaseMyChatTools.Key(int.Parse(e.CommandArgument.ToString()))));
                    InitData();
                    break;

            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("edit.aspx");
        }
    }
}
